package com.numberone.system.service.impl;

import com.numberone.common.support.Convert;
import com.numberone.system.domain.GoodDetailList;
import com.numberone.system.domain.GoodsDetail;
import com.numberone.system.mapper.GoodsDetailMapper;
import com.numberone.system.service.IGoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * 商品具体 服务层实现
 * 
 * @author numberone
 * @date 2020-09-28
 */
@Service
public class GoodsDetailServiceImpl implements IGoodsDetailService
{
	@Autowired
	private GoodsDetailMapper goodsDetailMapper;

	/**
     * 查询商品具体信息
     * 
     * @param id 商品具体ID
     * @return 商品具体信息
     */
    @Override
	public GoodsDetail selectGoodsDetailById(Long id)
	{
	    return goodsDetailMapper.selectGoodsDetailById(id);
	}
	
	/**
     * 查询商品具体列表
     * 
     * @param goodsDetail 商品具体信息
     * @return 商品具体集合
     */
	@Override
	public List<GoodsDetail> selectGoodsDetailList(GoodsDetail goodsDetail)
	{
	    return goodsDetailMapper.selectGoodsDetailList(goodsDetail);
	}
	
    /**
     * 新增商品具体
     * 
     * @param goodsDetail 商品具体信息
     * @return 结果
     */
	@Override
	public int insertGoodsDetail(GoodsDetail goodsDetail)
	{
	    return goodsDetailMapper.insertGoodsDetail(goodsDetail);
	}
	
	/**
     * 修改商品具体
     * 
     * @param goodsDetail 商品具体信息
     * @return 结果
     */
	@Override
	public int updateGoodsDetail(GoodsDetail goodsDetail)
	{
	    return goodsDetailMapper.updateGoodsDetail(goodsDetail);
	}

	/**
     * 删除商品具体对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteGoodsDetailByIds(String ids)
	{
		return goodsDetailMapper.deleteGoodsDetailByIds(Convert.toStrArray(ids));
	}
	/**
	 * 根据商品查询商品具体信息
	 * @param goodsId
	 * @return
	 */
	@Override
	public List<GoodsDetail> selectGoodsDetailByGood(Long goodsId) {
		List<GoodsDetail> goodsDetails = goodsDetailMapper.selectGoodsDetailByGood(goodsId);
		System.out.println("====="+ goodsDetails.size());
		for (GoodsDetail i : goodsDetails)
		{
//			List<GoodDetailList> goodDetailLists = goodsDetailMapper.selectDetailImgs(i.getSpecification());
//			i.setImgs(goodDetailLists);
			List<GoodDetailList> lists = goodsDetailMapper.selectDetailImgs(i.getSpecification());
//			List<GoodDetailList> list = new LinkedList<>();
//			for (GoodsDetail j : goodsDetail)
//			{
//				GoodDetailList goodDetailList = new GoodDetailList();
//				goodDetailList.setImg(j.getImg());
//				goodDetailList.setImginfo(j.getImgInfo());
//				list.add(goodDetailList);
//			}
			i.setImgs(lists);
		}
		return goodsDetails;
//		List<?> imgs = goodsDetailMapper.selectDetailImgs(goodsId);
//		List<?> details = goodsDetailMapper.selectDetails(goodsId);
//		GoodDetailList goodDetailList = new GoodDetailList();
//		goodDetailList.setImgs(imgs);
//		goodDetailList.setDetails(details);
//		return goodDetailList;
	}
}
